package com.zmm.zebulon.module.member.biz.dal.mysql.address;

import com.zmm.zebulon.module.member.biz.dal.dataobject.address.MemberAddressDO;
import com.zmm.zebulon.starter.mybatis.mybatis.core.mapper.BaseMapperX;
import com.zmm.zebulon.starter.mybatis.mybatis.core.query.LambdaQueryWrapperX;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * description: 用户地址 Mapper
 *
 * @author zebulon
 * package com.zmm.zebulon.module.member.biz.dal.mysql.address
 * name: MemberAddressMapper
 * date 2024/1/10 20:55
 */
@Mapper
public interface MemberAddressMapper extends BaseMapperX<MemberAddressDO> {

    default MemberAddressDO selectByIdAndUserId(Long id, Long userId) {
        return selectOne(MemberAddressDO::getId, id, MemberAddressDO::getUserId, userId);
    }

    default List<MemberAddressDO> selectListByUserIdAndDefaulted(Long userId, Boolean defaulted) {
        return selectList(new LambdaQueryWrapperX<MemberAddressDO>().eq(MemberAddressDO::getUserId, userId)
                .eqIfPresent(MemberAddressDO::getDefaultStatus, defaulted));
    }

}
